package chaoyue.study.safe;

/**
 * 使用volatile关键字修饰可以解决可见性的问题
 */
public class VisibilityTest2 {
    private volatile static boolean isOver = false;

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            System.out.println("thread start...");
            while (!isOver) {
            }
            System.out.println("thread over...");
        });
        thread.start();
        Thread.sleep(1000);
        isOver = true; // 主线程将共享变量内容修改，子线程能获取到变更后的最新值
    }
}
